package org.cheniy.domain.strategy.service.rule.tree.factory;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.cheniy.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import org.cheniy.domain.strategy.model.valobj.RuleTreeVO;
import org.cheniy.domain.strategy.service.rule.tree.ILogicTreeNode;
import org.cheniy.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import org.cheniy.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author cheniy
 * @description 规则树工厂，提供装配-提供map，规定返回结果对象
 * @create 2025/3/8 15:35
 */
@Service
public class DefaultTreeFactory {

    public Map<String, ILogicTreeNode> logicChainMap = new ConcurrentHashMap<>();

    // 构造注入
    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicChainMap) {
        this.logicChainMap = logicChainMap;
    }

    // 执行工厂引擎
    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicChainMap, ruleTreeVO);
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    // 过滤器返回的结果，用来判断被拦截还是放行
    public static class TreeActionEntity{
        /** 放行或拦截的枚举 */
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        /** 获得的策略奖品对象 */
        private StrategyAwardVO strategyAwardVO;
    }


    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    // 抽奖时，前置过滤器只需要返回id，
    // 但是中后，如果别拦截则会进入幸运奖，需要幸运奖的随机范围，则需要awardRuleValue参数
    public static class StrategyAwardVO {
        /** 抽奖奖品ID */
        private  Integer awardId;
        /** 获得幸运奖奖品的规则 */
        private  String awardRuleValue;
    }


}
